﻿using System;
using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;
namespace SilverSea.Video.Tools
{
	public class PagedWizard : Form
	{
		private Control control_0;
		private EventHandler eventHandler_0;
		private IContainer icontainer_0;
		private TabControl tabControl;
		private Button btnApply;
		private Button btnOK;
		private Button btnCancel;
		public event EventHandler Apply
		{
			add
			{
				EventHandler eventHandler = this.eventHandler_0;
				EventHandler eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler value2 = (EventHandler)Delegate.Combine(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange<EventHandler>(ref this.eventHandler_0, value2, eventHandler2);
				}
				while (eventHandler != eventHandler2);
			}
			remove
			{
				EventHandler eventHandler = this.eventHandler_0;
				EventHandler eventHandler2;
				do
				{
					eventHandler2 = eventHandler;
					EventHandler value2 = (EventHandler)Delegate.Remove(eventHandler2, value);
					eventHandler = Interlocked.CompareExchange<EventHandler>(ref this.eventHandler_0, value2, eventHandler2);
				}
				while (eventHandler != eventHandler2);
			}
		}
		public int SelectedPageIndex
		{
			get
			{
				return this.tabControl.SelectedIndex;
			}
		}
		public PagedWizard()
		{
			this.InitializeComponent();
		}
		public void AddPage(IWizardPage page)
		{
			Control control = (Control)page;
			TabPage tabPage = new TabPage();
			tabPage.TabIndex = this.tabControl.TabCount;
			tabPage.Text = page.PageName;
			this.tabControl.Controls.Add(tabPage);
			tabPage.Controls.Add(control);
			control.Dock = DockStyle.Fill;
			page.StateChanged += new EventHandler(this.method_2);
		}
		private void PagedWizard_Load(object sender, EventArgs e)
		{
			this.method_1(0);
		}
		private void method_0()
		{
			this.btnApply.Enabled = (this.control_0 != null && ((IWizardPage)this.control_0).Completed);
			this.btnOK.Enabled = true;
			foreach (Control control in this.tabControl.Controls)
			{
				if (!((IWizardPage)control.Controls[0]).Completed)
				{
					this.btnOK.Enabled = false;
					break;
				}
			}
		}
		private void method_1(int int_0)
		{
			if (this.tabControl.Controls.Count > 0)
			{
				this.control_0 = this.tabControl.Controls[int_0].Controls[0];
				IWizardPage wizardPage = (IWizardPage)this.control_0;
				wizardPage.Display();
				this.method_0();
			}
		}
		private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.method_1(this.tabControl.SelectedIndex);
		}
		private void btnApply_Click(object sender, EventArgs e)
		{
			if (((IWizardPage)this.control_0).Apply() && this.eventHandler_0 != null)
			{
				this.eventHandler_0(this, new EventArgs());
			}
		}
		private void btnOK_Click(object sender, EventArgs e)
		{
			foreach (Control control in this.tabControl.Controls)
			{
				if (!((IWizardPage)control.Controls[0]).Apply())
				{
					return;
				}
			}
			base.DialogResult = DialogResult.OK;
			base.Close();
		}
		private void method_2(object sender, EventArgs e)
		{
			this.method_0();
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.icontainer_0 != null)
			{
				this.icontainer_0.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PagedWizard));
            this.tabControl = new System.Windows.Forms.TabControl();
            this.btnApply = new System.Windows.Forms.Button();
            this.btnOK = new System.Windows.Forms.Button();
            this.btnCancel = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // tabControl
            // 
            this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.tabControl.Location = new System.Drawing.Point(12, 12);
            this.tabControl.Name = "tabControl";
            this.tabControl.SelectedIndex = 0;
            this.tabControl.Size = new System.Drawing.Size(520, 307);
            this.tabControl.TabIndex = 0;
            this.tabControl.SelectedIndexChanged += new System.EventHandler(this.tabControl_SelectedIndexChanged);
            // 
            // btnApply
            // 
            this.btnApply.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.btnApply.Location = new System.Drawing.Point(250, 328);
            this.btnApply.Name = "btnApply";
            this.btnApply.Size = new System.Drawing.Size(90, 28);
            this.btnApply.TabIndex = 1;
            this.btnApply.Text = "Áp dụng";
            this.btnApply.UseVisualStyleBackColor = true;
            this.btnApply.Click += new System.EventHandler(this.btnApply_Click);
            // 
            // btnOK
            // 
            this.btnOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.btnOK.Location = new System.Drawing.Point(346, 328);
            this.btnOK.Name = "btnOK";
            this.btnOK.Size = new System.Drawing.Size(90, 28);
            this.btnOK.TabIndex = 2;
            this.btnOK.Text = "Đồng ý";
            this.btnOK.UseVisualStyleBackColor = true;
            this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
            // 
            // btnCancel
            // 
            this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.btnCancel.Location = new System.Drawing.Point(442, 328);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(90, 28);
            this.btnCancel.TabIndex = 3;
            this.btnCancel.Text = "Hủy bỏ";
            this.btnCancel.UseVisualStyleBackColor = true;
            // 
            // PagedWizard
            // 
            this.CancelButton = this.btnCancel;
            this.ClientSize = new System.Drawing.Size(544, 368);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.btnOK);
            this.Controls.Add(this.btnApply);
            this.Controls.Add(this.tabControl);
            this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Margin = new System.Windows.Forms.Padding(4);
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "PagedWizard";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "PagedWizard";
            this.Load += new System.EventHandler(this.PagedWizard_Load);
            this.ResumeLayout(false);

		}
	}
}
